package com.library.dao;

import com.library.entity.TypeInfo;
import com.library.utils.DBUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TypeInfoDao {
    public List<TypeInfo> findAllTypes() {
        List<TypeInfo> typeList = new ArrayList<>();
        String sql = "SELECT * FROM type_info";
        try (Connection connection = DBUtils.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement(sql);
             ResultSet resultSet = preparedStatement.executeQuery()) {

            while (resultSet.next()) {
                TypeInfo typeInfo = new TypeInfo();
                typeInfo.setId(resultSet.getInt("id"));
                typeInfo.setName(resultSet.getString("name"));
                typeInfo.setRemarks(resultSet.getString("remarks"));
                typeList.add(typeInfo);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return typeList;
    }
}